package com.example.article.controller;

import com.example.common.util.R;
import com.example.model.article.dto.CollectionBehaviorDto;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.article.service.CollectionService;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.tags.Tag;

@RestController
@RequestMapping("/api/v1/")
@Tag(name = "收藏文章管理")
public class CollectionController {
    @Autowired
    private CollectionService collectionService;

    @PostMapping("/collection/behavior_collection")
    @Operation(summary = "收藏文章")
    public R collection(@RequestBody CollectionBehaviorDto collectionBehaviorDto) {
        boolean flag = collectionService.collection(collectionBehaviorDto);
        if (flag) {
            return R.ok(collectionBehaviorDto.getOperation() == 0 ? "收藏文章成功" : "取消收藏文章成功");
        } else {
            return R.error(collectionBehaviorDto.getOperation() == 1 ? "收藏失败" : "取消收藏文章失败");
        }
    }
}